package com.gemme.gemme.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gemme.gemme.R;
import com.gemme.gemme.shequ.GuanzhuSingleView;
import com.gemme.gemme.shequ.SheQUTuijianBean;
import com.gemme.gemme.shequ.ShequFansActivity;

import java.util.List;

public class GuanzhuHeadView extends RelativeLayout {
    private Context context;
    public GuanzhuHeadView(Context context) {
        this(context,null);
    }

    public GuanzhuHeadView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public GuanzhuHeadView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    TextView tv_more;
    LinearLayout ll_content;
    HorizontalScrollView scrollView;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.guanzhu_head_view,this);
        tv_more = findViewById(R.id.tv_more);
        tv_more.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, ShequFansActivity.class));
            }
        });

        ll_content = findViewById(R.id.ll_content);
        scrollView = findViewById(R.id.scrollView);
    }

    public void setData(SheQUTuijianBean bean) {
        try {
            ll_content.removeAllViews();
            List<SheQUTuijianBean.DataBean> data = bean.getData();
            if(data == null || data.size() == 0){
                scrollView.setVisibility(GONE);
            }else{
                scrollView.setVisibility(VISIBLE);
            }
            for (int i = 0; i < data.size(); i++) {
                SheQUTuijianBean.DataBean dataBean = data.get(i);
                GuanzhuSingleView guanzhuSingleView = new GuanzhuSingleView(context);
                guanzhuSingleView.setData(dataBean);
                ll_content.addView(guanzhuSingleView);
            }
        }catch (Exception e){

        }
    }
}
